package org.sgx.gwteditors.testgallery.gallery;

import java.util.List;
import java.util.Map;

import org.sgx.gwteditors.client.impl1.EditorFramework1;
import org.sgx.gwteditors.client.impl1.basetypes.HTML5File;
import org.sgx.gwteditors.client.impl1.misc.HTML5FileEditor;
import org.sgx.gwteditors.client.impl1.misc.HTML5FileEditor.FileReadListener;
import org.sgx.gwteditors.client.impl1.simple.IntegerEditorEntry;
import org.sgx.gwteditors.client.util.TestUtil;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.ExternalTextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
/**
 * Shows how to use the HTML5FileEditor - an editor that let the user drag&drop 1 or more files from desktop
 * @author sg
 *
 */
public class HTML5FileEditorTest1 implements Test {	
	
	@Override
	public void test(Panel parent) {
		new EditorFramework1().start(); //do not forget of initialize the gwteditors framework !
		final HTML5FileEditor ed = new HTML5FileEditor(); 
		parent.add(new Label("Please drag asome desktop files and dropped inthe following box:"));
		parent.add(ed.getWidget());
		parent.add(new Button("save files", new ClickHandler() {			
			@Override
			public void onClick(ClickEvent event) {
				ed.flush(new FileReadListener() {
					
					@Override
					public void ready(List<HTML5File> l) {
						List<HTML5File> files = ed.flush();
						String s = "Files: "; 
						for(HTML5File f : files) {
							s+=f;
						}
						Window.alert(s); 
					}
				}); 
				
			}
		})); 
	}
	
	
	//test stuff
	@Override
	public String getName() {
		return "html5File1";
	}

	@Override
	public String[] getTags() {		
		return null;
	}

	@Override
	public String getDescription() {
		return "Shows how to use the HTML5FileEditor - an editor that let the user drag&drop 1 or more files from desktop";
	}
	@Override
	public Map<String, ExternalTextResource> getJavaSources() {
		return TestUtil.getResource(getName(), TestResources.INSTANCE.HTML5FileEditorTest1());
	}
//	@Override
//	public String[] getJavaSources() {
//		return new String[]{TestResources.INSTANCE.HTML5FileEditorTest1().getText()};
//	}
}
